﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TimeTravel.Components;
using TimeTravel.Extentions;
using TimeTravel.IData;
using TimeTravel.DataProvider;
using TimeTravel.IServices;

namespace TimeTravel.Services
{
    public class RecentNewService:IRecentNewService
    {
        private static readonly IRecentNewData DataProvider = DataAccess.CreateDataInstance<IRecentNewData>();

        #region Implementation of IServiceBase<RecentNewInfo>

        /// <summary>
        /// 添加记录
        /// </summary>
        public int Add(RecentNewInfo news)
        {
            return DataProvider.Add(news);
        }

        /// <summary>
        /// 删除记录
        /// </summary>
        /// <param name="id"></param>
        public void Delete(int id)
        {
            if (id!=0)
            {
                DataProvider.Delete(id);
            }
        }

        /// <summary>
        /// 更新记录
        /// </summary>
        /// <param name="news"></param>
        public void Update(RecentNewInfo news)
        {
            if (news!=null && news.ID!=0)
            {
                DataProvider.Update(news);
            }
        }

        /// <summary>
        /// 获取所有
        /// </summary>
        /// <returns></returns>
        public IList<RecentNewInfo> GetAll()
        {
            return DataProvider.GetAll();
        }

        /// <summary>
        /// 根据条件获取
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public RecordSet<RecentNewInfo> GetBySearch(PageQueryInfo query)
        {
            if (query==null)
            {
                return new RecordSet<RecentNewInfo>();
            }
            return DataProvider.GetBySearch(query);
        }

        /// <summary>
        /// 获取详细信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public RecentNewInfo GetOne(int id)
        {
            if (id==0)
            {
                return null;
            }
            return DataProvider.GetOne(id);
        }

        /// <summary>
        /// 获取总数
        /// </summary>
        /// <returns></returns>
        public int GetTotalCount()
        {
            return DataProvider.GetTotalCount();
        }

        /// <summary>
        /// 更新查看次数
        /// </summary>
        /// <param name="id"></param>
        public void UpdateClickCount(int id)
        {
            if (id!=0)
            {
                DataProvider.UpdateClickCount(id);
            }
        }

        #endregion
    }
}
